<template>
  <div>
    <el-card>
      <div class="border">
        <span style="font-size: 17px;font-weight: bold">审核文档</span>
      </div>
      <div class="border1">
        <el-form :inline="true">
          <el-form-item label="标题：">
            <el-input
              class="mr5"
              v-model="formInfo.keywords"
              placeholder="请输入标题"
            ></el-input>
          </el-form-item>
          <el-form-item label="文档类型:">
            <el-select
              class="mr5"
              v-model="formInfo.categoryId"
              placeholder="请选择"
            >
              <el-option
                v-for="item in categoryList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="时间：">
            <el-date-picker
              class="mr5"
              v-model="value4"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" @click="search">
              搜索
            </el-button>
            <el-button icon="el-icon-s-open" type="primary" @click="clear">
              重置
            </el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-row style="text-align: center;padding:20px">
        <page-table
          :page-data="DocumentPageList"
          stripe
          border
          style="width: 100%;"
          :do-get-page-data="getMyRelease"
        >
          <el-table-column
            width="100"
            type="index"
            align="center"
            label="序号"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="title"
            label="标题"
            width="500"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <a class="task_title_a" @click="examine(scope.row)">{{
                scope.row.title
              }}</a>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="文档数量"
            prop="fileCount"
          ></el-table-column>

          <el-table-column
            prop="categoryName"
            align="center"
            label="文档类型"
          ></el-table-column>
          <el-table-column
            align="center"
            label="发送人"
            prop="createUserName"
          ></el-table-column>
          <el-table-column
            align="center"
            label="发送部门"
            show-overflow-tooltip
            prop="organizeName"
          ></el-table-column>
          <el-table-column
            prop="createTime"
            align="center"
            label="发送时间"
            width="200"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            fixed="right"
            align="center"
            width="200"
            label="管理"
          >
            <template slot-scope="scope">
              <el-tooltip content="查看" placement="top">
                <el-button
                  size="mini"
                  icon="el-icon-view"
                  @click="examine(scope.row)"
                ></el-button>
              </el-tooltip>
              <el-tooltip content="审核通过" placement="top">
                <el-button
                  size="mini"
                  icon="el-icon-check"
                  @click="verify(scope.row)"
                ></el-button>
              </el-tooltip>
              <el-tooltip content="审核不通过" placement="top">
                <el-button
                  size="mini"
                  icon="el-icon-close"
                  @click="verifyClose(scope.row)"
                ></el-button>
              </el-tooltip>
            </template>
          </el-table-column>
        </page-table>
      </el-row>
    </el-card>
    <el-dialog
      title="审核不通过:"
      :visible.sync="verifyCloseStatus"
      v-if="verifyCloseStatus"
      width="600px"
      @close="fail"
    >
      <el-row>
        <el-col :span="24" class="mt20">
          <el-form
            ref="form"
            :rules="rules"
            :model="formInfo1"
            label-width="90px"
          >
            <el-form-item prop="reason" label="拒绝理由:">
              <el-input
                v-model="formInfo1.reason"
                placeholder="请输入理由"
              ></el-input>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
      <div slot="footer">
        <el-button type="primary" @click="save">确定</el-button>
        <el-button @click="fail">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  created() {
    this.getMyRelease();
    this.getCategoryTree();
  },
  data() {
    return {
      value4: [],
      categoryList: [], //文档类型列表
      formInfo: {
        pageIndex: 1,
        pageSize: 10,
        keywords: "",
        categoryId: "",
        deleteFlag: 0,
        myAccept: 1,
        module: "DOCUMENT"
      },
      DocumentPageList: { records: [] },
      verifyCloseStatus: false,
      rowId: "",
      rules: {
        reason: [{ required: true, message: "请输入理由", trigger: "blur" }]
      },
      formInfo1: {
        reason: ""
      }
    };
  },
  methods: {
    save() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          let tem = {
            id: this.rowId,
            auditStatus: false,
            reason: this.formInfo1.reason
          };
          this.API.auditDocument({ body: tem }).then(ret => {
            this.success("审核成功");
            this.getMyRelease();
            this.fail();
          });
        }
      });
    },
    fail() {
      this.verifyCloseStatus = false;
      this.formInfo1 = {
        reason: ""
      };
      this.rowId = "";
    },
    //获取文档类型
    getCategoryTree() {
      this.API.getCategoryTree({ type: "DOCUMENT" }).then(res => {
        this.categoryList = res.data;
      });
    },
    //跳转至详情
    examine(row) {
      this.$router.push({ name: "examine", query: { row: row.id } });
    },
    verifyClose(row) {
      this.rowId = row.id;
      this.verifyCloseStatus = true;
    },
    //审核
    verify(row) {
      this.$confirm("确认审核通过当前文档?", "提示", {})
        .then(() => {
          let tem = {
            id: row.id,
            auditStatus: true
          };
          this.API.auditDocument({ body: tem }).then(ret => {
            this.success("审核通过成功");
            this.getMyRelease();
          });
        })
        .catch(() => {});
    },
    //获取分页
    getMyRelease(val) {
      let tem = Object.assign(this.formInfo, val);
      this.API.getDocumentPageList(tem).then(ret => {
        this.DocumentPageList = ret.data;
      });
    },
    //搜索
    search() {
      this.getMyRelease(1);
    },
    //重置
    clear() {
      this.formInfo = {
        pageIndex: 1,
        pageSize: 10,
        keywords: "",
        deleteFlag: 0,
        categoryId: "",
        myAccept: 1,
        module: "DOCUMENT"
      };
      this.value4 = [];
      this.getMyRelease(1);
    }
  }
};
</script>
<style scoped>
/deep/ .el-card__body {
  padding: 0;
}

.border {
  padding: 19px 0 19px 20px;
  border-bottom: 1px solid rgba(224, 238, 249, 1);
}

.border1 {
  padding: 19px 0 0px 20px;
  border-bottom: 1px solid rgba(224, 238, 249, 1);
}
</style>
